import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, Tree, TreeChildren, TreeParent } from 'typeorm';

@Entity('menus')
export class Menu {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ length: 100, comment: '菜单名称' })
  name: string;

  @Column({ length: 200, nullable: true, comment: '菜单路径' })
  path: string;

  @Column({ length: 200, nullable: true, comment: '前端组件路径' })
  component: string;

  @Column({ length: 100, nullable: true, comment: '菜单图标' })
  icon: string;

  @Column({ default: 0, comment: '排序权重' })
  sort: number;

  @Column({ default: 0, comment: '父菜单ID，0表示顶级菜单' })
  parent_id: number;

  @Column({ default: 1, comment: '菜单层级，1开始' })
  level: number;

  @Column({ 
    type: 'enum', 
    enum: ['menu', 'button'], 
    default: 'menu', 
    comment: '菜单类型：menu菜单，button按钮' 
  })
  type: 'menu' | 'button';

  @Column({ length: 200, nullable: true, comment: '权限标识' })
  permission: string;

  @Column({ default: true, comment: '是否可见' })
  is_visible: boolean;

  @Column({ default: true, comment: '是否启用' })
  is_enabled: boolean;

  @Column({ length: 500, nullable: true, comment: '外部链接' })
  external_link: string;

  @Column({ 
    type: 'enum', 
    enum: ['_self', '_blank', '_parent', '_top'], 
    default: '_self', 
    comment: '打开方式' 
  })
  target: '_self' | '_blank' | '_parent' | '_top';

  @Column({ type: 'json', nullable: true, comment: '元数据信息' })
  meta: any;

  @CreateDateColumn({ comment: '创建时间' })
  created_at: Date;

  @UpdateDateColumn({ comment: '更新时间' })
  updated_at: Date;

  // 虚拟字段，用于构建树形结构
  children?: Menu[];
  hasChildren?: boolean;
}
